/*
 * Name: $RCSfile: MemoryCache.java,v $
 * Version: $Revision: 1.1 $
 * Date: $Date: Dec 15, 2011 1:56:00 PM $
 *
 * Copyright (C) 2011 DirecTV, Inc. All rights reserved.
 */

package com.admissions.utils;

import java.lang.ref.SoftReference;
import java.util.HashMap;
import android.graphics.Bitmap;

/**
 * this class to cache image after downloaded an image.
 * 
 * @author DirecTV
 * 
 */
public class MemoryCache
{
    private HashMap<String, SoftReference<Bitmap>> cache = new HashMap<String, SoftReference<Bitmap>>();

    public Bitmap get(String id)
    {
        if (!cache.containsKey(id))
            return null;
        SoftReference<Bitmap> ref = cache.get(id);
        return ref.get();
    }

    public void put(String id, Bitmap bitmap)
    {
        cache.put(id, new SoftReference<Bitmap>(bitmap));
    }

    public void clear()
    {
        cache.clear();
    }
}